#include <iostream>
#include <string>
#include <jsoncpp/json/json.h>

int main()
{
    Json::Value root;
    root["name"] = "zhangsan";
    root["age"] = 18;
    root["sex"] = "man";

    // 1. 使用root.toStyledString()序列化
    std::string s1 = root.toStyledString();
    std::cout << s1 << std::endl;

    // 2.反序列化
    Json::Reader reader;
    reader.parse(s1, root);

    std::string name = root["name"].asString();
    int age = root["age"].asInt();
    std::string sex = root["sex"].asString();

    std::cout << "name->" << name << std::endl;
    std::cout << "age->" << age << std::endl;
    std::cout << "sex->" << sex << std::endl;






    // 2. 使用StyledWriter对象的write方法进行序列化
    //Json::StyledWriter writer;
    //std::string s2 = writer.write(root);
    //std::cout << s2 << std::endl;

    //// 3. 使用FastWriter对象的write方法进行序列化
    //Json::FastWriter wr;
    //std::string s3 = wr.write(root);
    //std::cout << s3 << std::endl;

    //// 4. 使用StreamWriterBuidler 对象new一个witer对象
    //// 通过new出来的对象，将root数据，写入到一个字符串流中
    //Json::StreamWriterBuilder swb;
    //std::unique_ptr<Json::StreamWriter> wri(swb.newStreamWriter());
    //std::stringstream ss;
    //wri->write(root, &ss);
    //std::cout << ss.str() << std::endl;

    return 0;
}